package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.project.system.service.ISmProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.Map;

/**
 * 首页
 */
@RestController
public class SysIndexController {

    @Autowired
    private RuoYiConfig ruoyiConfig;

    @Autowired
    private ISmProductService productService;

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private RedisCache redisCache;

    /**
     * 访问首页，提示语
     */
    @RequestMapping("/")
    public String index() {
        return StringUtils.format("欢迎使用{}后台管理框架，当前版本：v{}，请通过前端地址访问。", ruoyiConfig.getName(), ruoyiConfig.getVersion());
    }

    @GetMapping("/statistic")
    public AjaxResult statistic() {
        AjaxResult result = new AjaxResult();

        Map<String, Object> map = userMapper.statisticUser();
        map.put("TN", (Long) map.get("R2") + (Long) map.get("R3") + (Long) map.get("R4") + (Long) map.get("R5"));
        map.putAll(userMapper.statisticQueryAndPayAndIncome());

        result.put("sta_set", map);
        result.put("option", productService.selectOption());
        return result;
    }


}
